import Configure from '../guoxin-configure/configure.vue'
import Pages from '../../../pages/pages.vue'
import { setMenuType, getGuoxinList, showMsg } from '../../../../vuex/action'

export default {
  name: 'guoxin-list',
  components: {
    'guoxin-configure': Configure,
    'vue-pages': Pages
  },
  data() {
    return {
      searchPhone: '',
      showConfigure: false,
      guoxinList: [],
      ac: {
        status: '',
        phone: ''
      },
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      }
    }
  },
  vuex: {
    getters: {
      fresh: state => state.guoxinListNeedFresh
    },
    actions: {
      xSetMenuType: setMenuType,
      xGetGuoxinList: getGuoxinList,
      xShowMsg: showMsg
    }
  },
  ready() {
    this.xSetMenuType('activity')
    this.getList({})
  },
  methods: {
    getList({start=this.pages.start, limit=this.pages.limit, phone=this.searchPhone}) {
      this.xGetGuoxinList({
        start: start,
        limit: limit,
        phone: phone
      })
        .then((data) => {
          this.guoxinList = data.list
          this.pages.totalPages = Math.ceil(data.totalcount / limit)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    modifyAc(list) {
      this.showConfigure = true
      this.ac = list
    },
    goInviteList(phone) {
      this.$route.router.go('/invite/' + phone)
    }
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
